package fly.util;

import fly.help.PrintSupport;

import java.io.*;
import java.util.Properties;
import java.util.Set;

public class PropertiesDemo {


    public static void main(String[] args) {
        PrintSupport.sout("1");

        Properties pt = new Properties();

        InputStream in = null;
        String filePath = "./JDKLib/resources/propertiesDemo.properties";
        try {
            in = new FileInputStream( filePath); // 只能 英文
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        try {
            pt.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }

        Set<String> sstr = pt.stringPropertyNames();
        for (String str: sstr) {
            System.out.print(pt.getProperty(str) + ";\t");
        }

        PrintSupport.sout("2");
        pt.clear(); // 父类的方法

        Reader rd = null;
        try {
            rd = new FileReader(filePath); // 适合中文
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        try {
            pt.load(rd);
        } catch (IOException e) {
            e.printStackTrace();
        }

         sstr = pt.stringPropertyNames();
        for (String str: sstr) {
            System.out.print(pt.getProperty(str) + ";\t");
        }

    }
}
